const main = require("../models");
const router = require("koa-router")();
router.post("/doRegister",async ctx=>{
    console.log(ctx.request.body);
    var {username,pwd} = ctx.request.body;
    var table = await main("user")
    var res = await table.find({username}).toArray();
    console.log(res);
    if (res.length) {
        ctx.body = "<script>alert('用户名已经被注册');location.href='/register'</script>"
    } else {
        ctx.cookies.set("register","success")
        var res = await table.insertOne({ username, pwd });
        ctx.body = "<script>alert('注册成功,请登陆');location.href='/login'</script>"
    }
    
})

module.exports = router;